<template>
    <div>
        <el-form ref="form" :model="obj.data" label-width="80px">
            <el-form-item label="车位名称" prop="name" :rules="[formRulesMixin.notNull]">
                <el-input v-model="obj.data.name" clearable autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="分类" prop="type"  :rules="[formRulesMixin.notNull]">
                <el-select v-model="obj.data.type" placeholder="类别" class="search_select" clearable>
                    <el-option v-for="(item,index) in globalData.parkingTypeList" :key="index" :label="item.text" :value="item.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="车位说明" prop="memo" :rules="[formRulesMixin.notNull]">
                <el-input v-model="obj.data.memo" clearable autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item class="dialog-btns-item">
                <div class="dialog-btns">
                    <span class="btn clear" @click="$emit('close')">取消</span>
                    <span class="btn sub ml10" @click.prevent="upData">提交</span>
                </div>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup>
    import { reactive,ref,getCurrentInstance,toRaw,inject } from 'vue'
    import UpFileM from "@/components/upfile_multiple.vue"
    import Editer from "@/components/editer.vue"
    let { proxy } = getCurrentInstance()
    const props = defineProps({
        param: { type: Object, default: {
            "parking_id":"0",
            "name":"",
            "type":"",
            "memo":""
        } }
    })
    let obj = reactive({
        data:{
            "parking_id": props.param.parking_id,
            "name": props.param.name,
            "type": Number(props.param.type),
            "memo": props.param.memo
        }
    })
    let upData = () => {
        proxy.$refs['form'].validate(valid => {
            if (valid) {
                proxy.$ajax({
                    url: 'parking/design',
                    data: obj.data,
                    bfLoading: true,
                    timeout:60000
                }).then(d => {
                    if(d.success){
                        proxy.elMessageMixin(`${obj.data.id>0?'修改':"添加"}成功`, 'success')
                        proxy.$emit('init')
                        proxy.$emit('close')
                    }else{
                        proxy.elMessageMixin(d.err, 'error')
                    }
                }).catch(() => { })
            }else{
                return false
            }
        })
    }
</script>

<style scoped>
</style>